0
0
PHPprogramming~20 mins

Continue statement with levels in PHP - Mini Project: Build & Apply

Choose your learning style9 modes available
Continue Statement with Levels in PHP
📖 Scenario: Imagine you are organizing a small event with multiple sessions. You want to skip certain sessions or parts of sessions based on specific conditions.
🎯 Goal: You will write a PHP script that uses nested loops to represent sessions and their parts. You will use the continue statement with levels to skip parts or entire sessions.
📋 What You'll Learn
Create a nested loop structure with two levels: sessions and parts
Use a continue statement with a level to skip a part inside a session
Use a continue statement with a level to skip an entire session
Print the parts that are not skipped
💡 Why This Matters
🌍 Real World
Skipping parts of nested loops is useful when processing multi-level data, like events with sessions and parts, or files with folders and subfolders.
💼 Career
Understanding loop control with levels helps in writing efficient PHP scripts for web applications, data processing, and automation tasks.
Progress0 / 4 steps
1
Create nested loops for sessions and parts
Create a for loop with variable $session from 1 to 3 and inside it create another for loop with variable $part from 1 to 4.
PHP
Need a hint?

Use two for loops, one inside the other, with the exact variable names $session and $part.

2
Add a condition to skip part 3 in session 2
Add an if statement inside the inner loop to check if $session is 2 and $part is 3. Use continue 1; to skip only this part.
PHP
Need a hint?

Use continue 1; to skip only the current iteration of the inner loop.

3
Add a condition to skip entire session 3
Add an if statement inside the inner loop to check if $session is 3. Use continue 2; to skip the entire session including all its parts.
PHP
Need a hint?

Use continue 2; to skip the current iteration of the outer loop from inside the inner loop.

4
Print the session and part numbers that are not skipped
Inside the inner loop, after the continue statements, add a print statement to display "Session $session - Part $part\n".
PHP
Need a hint?

Use print("Session $session - Part $part\n"); to show the current session and part.