// ControlFlow.java — if/else, switch expressions and loops.
import java.util.List;

public class ControlFlow {

    public static void main(String[] args) {
        int quantity = 120;

        // if / else if / else
        if (quantity > 100) {
            System.out.println("Bulk order");
        } else if (quantity > 10) {
            System.out.println("Standard order");
        } else {
            System.out.println("Small order");
        }

        // Ternary operator: a compact if/else that returns a value
        String shipping = quantity > 50 ? "Free" : "Paid";
        System.out.println("Shipping: " + shipping);

        // Switch expression (Java 14+): no fall-through, returns a value
        String status = "SHIPPED";
        String message = switch (status) {
            case "NEW" -> "Order received";
            case "PICKING", "PACKING" -> "Being prepared";
            case "SHIPPED" -> "On its way";
            default -> "Unknown status";
        };
        System.out.println(message);

        // Classic for loop
        for (int i = 1; i <= 3; i++) {
            System.out.println("Line " + i);
        }

        // Enhanced for loop over a collection
        List<String> items = List.of("AX-200", "BX-310", "CX-420");
        for (String item : items) {
            System.out.println("Item: " + item);
        }

        // while loop
        int retries = 0;
        while (retries < 3) {
            retries++;
            System.out.println("Attempt " + retries);
        }

        // break and continue
        for (int i = 1; i <= 10; i++) {
            if (i % 2 == 0) continue;   // skip even numbers
            if (i > 7) break;           // stop the loop
            System.out.println("Odd: " + i);
        }
    }
}
