rava2
home
documentation
examples
/* retoor <retoor@molodetz.nl> */ public class Main { public static void main(String[] args) { System.out.println("Testing early returns in blocks..."); System.out.println("Test true: " + testReturn(true)); System.out.println("Test false: " + testReturn(false)); System.out.println("Testing return in loop..."); System.out.println("Loop result (5): " + testLoopReturn(5)); System.out.println("Loop result (15): " + testLoopReturn(15)); } static String testReturn(boolean condition) { if (condition) { return "Early Return Detected"; } return "Normal Return Detected"; } static int testLoopReturn(int limit) { for (int i = 0; i < 10; i++) { if (i == limit) { return i * 10; } } return -1; } }
run program
ready