do while cycle Java basic example

do while Java example

public class MainClass {
	public static void main(String[] arg) {
			String[] arrayOfString = { "Hello", "people", "hello", "world!" };
			int i = 0;
                        // first cycle is always executed
			do {
				System.out.println("Loop: " + i);
				System.out.println(arrayOfString[i]);
				i++;
 
			}while ( i == -1 );
	}
}
/*
Loop: 0
Hello
*/
 
public class MainClass {
	public static void main(String[] arg) {
			String[] arrayOfString = { "Hello", "people", "hello", "world!" };
			int i = 0;
			do {
				System.out.println("Loop: " + i);
				System.out.println(arrayOfString[i]);
				i++;
 
			}while ( i < arrayOfString.length );
	}
}
/*
Loop: 0
Hello
Loop: 1
people
Loop: 2
hello
Loop: 3
world!
*/
This entry was posted in Android Examples Code and tagged , , , , . Bookmark the permalink.


Comments are closed.

7,431 views