Ruby has conditional initialization. Apparently Java doesn't or doesn't it? I am trying to write more severely to limit the range as little as possible.
import java.io.*;
import java.util.*;
public class InitFor{
public static void main(String[] args){
for(int i=7,k=999;i+((String h="hello").size())<10;i++){}
System.out.println("It should be: hello = "+h);
}
}
Mistakes
Press ENTER or type command to continue
InitFor.java:8: ')' expected
for(int i=7,k=999;i+((String h="hello").size())<10;i++){}
^
Puzzles
- Is it possible to assign a value to a declared value during a loop? YES code1
- Is assignment in for-loop conditional? YES code2
- conditional init NO
- Can you assign different types of values ββin a loop? YES in reply
- Some rule for initializing inside loops? Declare outside to access values ββlater, what about init? (?)
1. CODE
import java.io.*;
import java.util.*;
public class InitFor{
public static void main(String[] args){
int k=5;
while((k=(k%3)+1)!=1){
System.out.println(k);
}
}
}
2. CODE
import java.io.*;
import java.util.*;
public class InitFor{
public static void main(String[] args){
int k=5;
for(;(k=(k%3)+1)!=1;){
System.out.println(k);
}
System.out.println(k);
}
}
Part of the original problem with many different types of assignments and initializations is 100 lines of code in one layer
for(int t=0,size=(File[] fs=((File f=f.getParentFile()).listFiles(filt))).size();fs==null;t++){if(t>maxDepth){throw new Exception("No dir to read");}}