+ All Categories
Home > Documents > מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input =...

מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input =...

Date post: 21-Dec-2015
Category:
View: 236 times
Download: 3 times
Share this document with a friend
24
הההה הההה הההההה
Transcript
Page 1: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

מבני בקרהלולאות

Page 2: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

CASEפקודת Module Module1

Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A is for Apple") Case "B" Console.WriteLine("B is for Boy") Case "C" Console.WriteLine("C is for Cat") Case Else Console.WriteLine("Not defined") End Select Console.ReadKey() End SubEnd Module

Page 3: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

- 2מבוא לתכנות למנע"ס - שבוע מספר מאיר קומר - סמסטר ב' - תשס"ו

iterationאיטראציה - בצע עדבצע עד

s1 תנאי

Page 4: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

- 2מבוא לתכנות למנע"ס - שבוע מספר מאיר קומר - סמסטר ב' - תשס"ו

iterationאיטראציה - כל עודכל עוד

s1

תנאי

Page 5: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

שני סוגי לולאות

לולאות במספר קבוע של פעמים•

)Eventלולאות עד אירוע מסוים (•

Page 6: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

לולאות במספר קבוע של פעמים

Module Module1

Sub Main() Dim i As Integer = 0 While (i < 100) Console.WriteLine("I love computers") i = i + 1 End While Console.ReadKey() End SubEnd Module

Page 7: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

FORקיצור דרך:

Module Module1

Sub Main() Dim i As Integer For i = 1 To 100 Console.WriteLine("I STILL love computers") Next i ' or just Next Console.ReadKey() End SubEnd Module

Page 8: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

FORקיצור דרך: STEPהמושג

Module Module1

Sub Main() Dim i As Integer For i = 100 To 1 Step -5 Console.Write("The square root of " & i) Console.Write(" is " & Math.Sqrt(i)) Console.WriteLine() Next i ' or just Next Console.ReadKey() End SubEnd Module

Page 9: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

לולאות עד אירועModule Module1

Sub Main() Dim x As Char Dim counter As Integer = 0 x = Console.ReadLine() If (x <> ".") Then counter = counter + 1 End If While (x <> ".") x = Console.ReadLine() If (x <> ".") Then counter = counter + 1 End If End While Console.WriteLine("The counter is " & counter) Console.ReadKey() End SubEnd Module

Page 10: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

DO WHILEModule Module1

Sub Main() Dim x As Char Dim counter As Integer = 0 Do x = Console.ReadLine() If (x <> ".") Then counter = counter + 1 End If Loop While (x <> ".") Console.WriteLine("The counter is " & counter) Console.ReadKey() End SubEnd Module

Page 11: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

LOOP UNTIL

Module Module1

Sub Main() Dim counter As Integer = 0 Do Until (counter = 10) Console.WriteLine("What is this " & counter) counter = counter + 1 Loop Console.ReadKey() End SubEnd Module

Page 12: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

דוגמא נוספתModule Module1

Sub Main() Dim x As Char Dim counter As Integer = 0 x = Console.ReadLine() Do Until (x = ".") x = Console.ReadLine() counter = counter + 1 Loop Console.WriteLine("The counter is " & counter) Console.ReadKey() End SubEnd Module

Page 13: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

ועוד דוגמא נוספתModule Module1

Sub Main() Dim x As String Dim counter As Integer = 0 Do Until (x = "avi") Console.WriteLine("Please enter a word") x = Console.ReadLine() counter = counter + 1 Loop Console.WriteLine("The counter is " & counter) Console.ReadKey() End SubEnd Module

Page 14: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

מספרים אקראייםImports System.RandomModule Module1

Sub Main() Dim RandomNumber As Integer Dim RandomClass As New Random() Dim i As Integer For i = 1 To 20 RandomNumber = RandomClass.Next(1, 100) Console.WriteLine("the number is " & RandomNumber) Next i Console.ReadKey() End SubEnd Module

Page 15: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

משחקי קוביותImports System.RandomModule Module1

Sub Main() Dim die1, die2 As Integer Dim RandomClass As New Random() Dim i As Integer For i = i To 20 die1 = RandomClass.Next(1, 6) die2 = RandomClass.Next(1, 6) Console.WriteLine("You rolled " & die1 & " and " & die2) Next i Console.ReadKey() End SubEnd Module

Page 16: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

משחק ניחושImports System.RandomModule Module1

Sub Main() Dim num, guess As Integer Dim RandomClass As New Random() num = RandomClass.Next(1, 100) Do Console.WriteLine("Please try to guess the number") guess = Console.ReadLine() If (guess > num) Then Console.WriteLine("You guessed too high") ElseIf (guess < num) Then Console.WriteLine("You guessed too low") Else Console.WriteLine("You got it") End If Loop While (num <> guess) Console.ReadKey() End SubEnd Module

Page 17: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

- 4מבוא לתכנות למנע"ס - שבוע מספר מאיר קומר - סמסטר ב' - תשס"ו

LOOPSלולאות -

For i = 1 to 2

s = s + 1

Next j

s = 0

For j = 1 to 4

Next i

i j s01 1

2 1

3 2

4 3

2 41

52

63

74

8

Page 18: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

לולאות בתוך לולאותModule Module1

Sub Main() Dim i, j As Integer For i = 1 To 5 For j = 1 To i Console.Write(j) Next j Console.WriteLine() Next i Console.ReadKey() End SubEnd Module

Page 19: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

Module Module1מספרים ראשוניים Sub Main() Dim i, factor, num As Integer Dim isprime As Boolean For num = 2 To 30000 isprime = True factor = 0 'Now check if it was divisible For i = 2 To num - 1 If (num Mod i = 0) Then isprime = False factor = i End If Next If (isprime) Then Console.WriteLine("The number " &num & " is prime") Else Console.WriteLine(i & " is divisible by " & factor) End If Next Console.ReadKey() End SubEnd Module

Page 20: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

בקבציםFORלולאות Imports System.IOModule Module1

Sub Main() Dim Input As Integer Dim objStreamReader As StreamReader objStreamReader = File.OpenText(“z:\numbers.txt") Dim i As Integer For i = 1 To 10 Input = objStreamReader.ReadLine() Console.WriteLine("I read " & Input) Next Console.ReadKey() End Sub

End Module

Page 21: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

לולאה בקבצים עד אירועImports System.IOModule Module1 Sub Main() Dim Input As Integer Dim sum = 0, count = 0 Dim objStreamReader As StreamReader objStreamReader = File.OpenText(“z:\KBTest.txt") Do Until Input = -1 Input = objStreamReader.ReadLine() If (Input <> -1) Then sum += Input count += 1 End If Loop Console.WriteLine("The Average is " & sum / count) Console.ReadKey() End SubEnd Module

Page 22: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

?IFלמה אני צריך את הImports System.IOModule Module1

Sub Main() Dim Input As Integer = 0 Dim sum = 0, count = 0 Dim objStreamReader As StreamReader objStreamReader = File.OpenText(“z:\KBTest.txt") Do Until Input = -1 sum += Input count += 1 Input = objStreamReader.ReadLine() Loop Console.WriteLine("The Average is " & sum / (count - 1)) Console.ReadKey() End Sub

End Module

Page 23: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

EOFלולאות Imports System.IOModule Module1

Sub Main() Dim Input As String = "" Dim objStreamReader As StreamReader objStreamReader = File.OpenText(“z:\KBTest.txt") Do Until Input Is Nothing Input = objStreamReader.ReadLine() Console.WriteLine("I read " & Input) Loop Console.ReadKey() End Sub

End Module

Page 24: מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.

עם מספריםEOF לולאות Imports System.IOModule Module1

Sub Main() Dim Input As String = "" Dim temp As Integer Dim objStreamReader As StreamReader objStreamReader = File.OpenText("z:\numbers.txt") Do Until Input Is Nothing Input = objStreamReader.ReadLine() temp = Input Console.WriteLine("I read " & Input + 2) Loop Console.ReadKey() End Sub

End Module


Recommended