0% found this document useful (0 votes)
14 views3 pages

Krishiv Patel Beginner Journal

Code

Uploaded by

Hockey for life
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Krishiv Patel Beginner Journal

Code

Uploaded by

Hockey for life
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Journal 1: Understanding Conditional Statements, Loops, and Constants

Name: Krishiv Patel

Instructor: Mr. Berry

Date: September 25, 2024

1. Conditional Statements (If Statements):

If statements let us make decisions in our code. They check if something is true, and if it is, they do

something. Here's an example:

if (x == 3) {

System.out.println("X is 3");

This code checks if the value of x is 3. If it is, it prints "X is 3".

2. Loops (Repetition Statements):

Loops help us run the same code multiple times without having to write it again and again. Some

types of loops are do, while, and for loops. Here's a simple example of a do-while loop:

do {

System.out.println("Hello");

} while (x == 2);
In this loop, the message "Hello" will print at least once, even if x is not 2.

3. Constants:

Constants are values that don't change while the program runs. We use the word 'final' to create a

constant. For example:

final int AGE = 7;

This means AGE will always be 7 in the program.

4. Loop Examples:

- Do-While Loop:

do {

// Code here

} while (condition);

- While Loop:

int x = 3;

while (x < 2) {

x += 2;

System.out.println(x);

- For Loop:

for (int i = 0; i < 4; i++) {


System.out.println("Yes");

5. The Difference Between Do-While and While Loops:

A do-while loop always runs the code inside it at least once before checking if the condition is true.

A while loop checks the condition first, so it might not run the code at all if the condition is false from

the start.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy