+ 1

I could not figure it out.

how this works. public class Program { public static void main(String[] args) { int i,j; for(i=1;i<4;i++){ for(j=1;j<2;j++){ System.out.println("v"); System.out.println("8"); } } } }

23rd Jun 2018, 7:03 PM
stephen haokip
stephen haokip - avatar
4 Answers
+ 11
first loop is execute 3 time for i=1,2,3 and second for loop is execute one time because 1<2 so only one time condition true and loop body executed so for i = 1 the inner loop print v,8 for i = 2 the inner loop print v,8 for i = 3 the inner loop print v,8 so output came as v 8 v 8 v 8
23rd Jun 2018, 7:11 PM
+ 7
I don’t know exactly what you want, but it’s basically two loops, one inside the other, or nested, printing out v and 8. if the first for statement is true, it moves to the second for statement, which prints the v and 8 out.
23rd Jun 2018, 7:10 PM
Jax - avatar
+ 2
thank q pal
23rd Jun 2018, 7:14 PM
stephen haokip
stephen haokip - avatar
+ 2
In this code there are two nested for loops. First the inner loop iterates, after the loop ends the outer loop is iterating one time and again the inner loop starts.You can read more here https://study.com/academy/lesson/nested-for-loops-in-java.html
23rd Jun 2018, 7:18 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar