Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20231104-KursPodstawowyALX
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
20231104-KursPodstawowyALX
Commits
f97e33ea
Commit
f97e33ea
authored
Nov 18, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
teria pętli for
parent
68560c66
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
1 deletions
+39
-1
PierwszePetle.java
src/main/java/p05_petle/teoria/PierwszePetle.java
+39
-1
No files found.
src/main/java/p05_petle/teoria/PierwszePetle.java
View file @
f97e33ea
...
...
@@ -5,14 +5,52 @@ public class PierwszePetle {
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Początek programu"
);
System
.
out
.
println
(
"Pętla while:"
);
int
a
=
1
;
while
(
a
<
5
)
{
System
.
out
.
println
(
"a = "
+
a
);
a
++;
}
System
.
out
.
println
(
"Koniec pętli while. Teraz a = "
+
a
);
System
.
out
.
println
();
System
.
out
.
println
(
"----------------\n"
);
System
.
out
.
println
(
"Pętla do-while:"
);
int
b
=
1
;
do
{
System
.
out
.
println
(
"b = "
+
b
);
b
++;
}
while
(
b
<
5
);
System
.
out
.
println
(
"Koniec pętli do-while. Teraz b = "
+
b
);
System
.
out
.
println
(
"----------------\n"
);
System
.
out
.
println
(
"Pętla for:"
);
for
(
int
i
=
1
;
i
<
5
;
i
++)
{
System
.
out
.
println
(
"i = "
+
i
);
}
System
.
out
.
println
(
"Koniec pętli for."
);
//NK System.out.println("Teraz i = " + i);
// Najczęściej zmienną sterującą pętli for deklaruje się wewnątrz pętli,
// wtedy nie ma do niej już dostępu po zakończeniu - ALE TO JEST DOBRA PRAKTYKA.
System
.
out
.
println
(
"----------------\n"
);
// Gdyby nam zależało, aby końcową wartość zminnej odczytać po zakończeniu pętli for, podobnie jak robiliśmy w while,
// to można zadeklarować zmienną jeszcze przed pętlą.
int
c
;
System
.
out
.
println
(
"Pętla for 2:"
);
for
(
c
=
1
;
c
<
5
;
c
++)
{
System
.
out
.
println
(
"c = "
+
c
);
}
System
.
out
.
println
(
"Koniec pętli for. Teraz c = "
+
c
);
System
.
out
.
println
(
"----------------\n"
);
System
.
out
.
println
(
"Pętla for-each:"
);
// Przeglądanie elementów tablicy lub kolekcji (do przeglądania obiektów iterowalnych / Iterable)
String
[]
tablica
=
{
"Java"
,
"Python"
,
"JS"
,
"C++"
};
for
(
String
element
:
tablica
)
{
System
.
out
.
println
(
" * "
+
element
);
}
System
.
out
.
println
(
"Koniec pętli for-each."
);
System
.
out
.
println
(
"----------------"
);
System
.
out
.
println
(
"Koniec programu"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment