Prof. Dr. Barne Kleinen

Website of Prof. Dr. Barne Kleinen, Professor for Media Informatics (Bachelor/Master) at HTW Berlin

While Loop

Material in   Courses: Info1   Tags: Info1-Script Java  

While Loop

Structure


// before loop

while(condition){
    // loop body
} 

// after loop

shorter

flowchart TD
    S[Start]
    C{cond?}
    L(LOOP BODY)
    E(End)
    S --> C
    
    C --true?--> L
    L --> C
    C -->|false?| E

longer version

flowchart TD
    A[Start]
    B(before loop)
    L(loop body)
    F(after loop)

    A --> B
    B --> C{condition true?}
    L --> C
    C --true--> L
    C -->|false| F
   
    F -->G[End]
## Examples

## Further Reading

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html