Skip to content

Instantly share code, notes, and snippets.

@HamsterofDeath
Created March 23, 2023 19:00
Show Gist options
  • Save HamsterofDeath/19be59d116362056ac628cd231cc0a77 to your computer and use it in GitHub Desktop.
Save HamsterofDeath/19be59d116362056ac628cd231cc0a77 to your computer and use it in GitHub Desktop.
package superprof;
public class Unroll {
static int zaehler = 0;
public static void main(String[] args) {
int x = 1;
// Test '1'
System.out.print('1' + "\n\r");
zaehler++;
boolean test1 = true;
while (true) {
// Test '2'
System.out.print('2' + "\n\r");
zaehler++;
boolean test2 = true;
// Check condition
if (!(test2 && (x <= 2))) {
break;
}
x++;
// Test '4'
System.out.print('4' + "\n\r");
zaehler++;
// Test '3'
System.out.print('3' + "\n\r");
zaehler++;
boolean test3 = true;
}
System.out.println("Zähler = " + zaehler);
}
static boolean test(char num) {
System.out.print(num + "\n\r");
zaehler++;
return true;
}
// The main method initializes variable x to 1.
// The test('1') call is executed, incrementing the counter zaehler and printing "1\n\r".
// Then the test('2') call is executed, incrementing the counter zaehler and printing "2\n\r".
// If the condition (x <= 2) is true, the loop continues:
//
// Increment the value of x by 1.
// Execute the test('4') call, incrementing the counter zaehler and printing "4\n\r".
// Execute the test('3') call, incrementing the counter zaehler and printing "3\n\r".
//
//After the execution of test('3'), the loop starts again from step 3 (executing test('2') call). The loop continues to iterate as long as the condition (x <= 2) remains true. When the condition becomes false, the loop breaks.
//
//After the loop exits, the program prints the value of zaehler with the message "Zähler = " followed by the counter value.
//
//Here's a summary of the code's execution:
//
// Initialize x to 1.
// Execute test('1') and increment the counter.
// Enter the loop:
// a. Execute test('2') and increment the counter.
// b. If the condition (x <= 2) is false, break the loop.
// c. Increment x.
// d. Execute test('4') and increment the counter.
// e. Execute test('3') and increment the counter.
// f. Repeat steps a-e until the condition (x <= 2) becomes false.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment