تابع
سلسلة أوامر الدوران
أصنع حلقة أوامر
إعداد : Ashalshaikh
رابعا :: أمر الدوران سهل جدا Do
يقوم بعمل دائرة إلى أن يحدث شرط الخروج ,,
هو شبيه جدا بـ While ولكن :
While : شرط البقاء في الحلقة
Do : شرط الخروج من الحلقة
ملاحظة :: لا يمكن وضع Do يدور إلى الأبد ولكن ممكن نتحايل عليه :d:
الآن ناخذ مثال ::
كود:
[CENTER][B][FONT=Times New Roman][SIZE=3][COLOR=blue]Do [/COLOR][/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=darkred]$dd[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] = [/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=royalblue][COLOR=navy]Msgbox[/COLOR] (4,"","هل تريد الخروج")[/COLOR][/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=blue]Until[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=darkred] $dd[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] = 6[/SIZE][/FONT][/B][/CENTER]
سيخرج إذا ضغطت على نعم ,,
# نلاحظ هنا فرق بينه وبين While ,,,, فيWhile لا بد من تعريف المتغير قبل الدخول في الحلقة ,, ولكن هنا يمكن تعريفه داخل الحلقة بدون مشاكل ,,
ناخذ مثال آخر ,,
كالعادة ,, يعد من 0 إلى 5
كود:
[CENTER][B][FONT=Times New Roman][SIZE=3][COLOR=darkred]$Num[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] = 0[/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=blue]Do [/COLOR][/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=navy]Msgbox[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=royalblue](0,"",[COLOR=darkred]$Num[/COLOR] )[/COLOR][/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=darkred]$Num[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] =[/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=darkred] $Num[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] + [/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=purple]1[/COLOR][/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=blue]Until [/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=darkred]$Num[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] = [/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=darkorchid]6[/COLOR][/SIZE][/FONT][/B][/CENTER]
لماذا شرط الخروج 6 مع إننا نريده يعد إلى 5 ؟ أنتظر إجابة منكم !!
نجرب شي ثاني ,,
نريده يعد من 1 إلى 5 ولكن يقفز الرقم 3
كود:
[CENTER][B][FONT=Times New Roman][SIZE=3][COLOR=darkred]$Num[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] = [/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=purple]0[/COLOR][/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=blue]Do [/COLOR][/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=darkred] $Num[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] = [/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=darkred]$Num[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] + [/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=purple]1[/COLOR][/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=blue]If [/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=darkred]$Num[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] = [COLOR=purple]3[/COLOR] [/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=blue]Then ContinueLoop[/COLOR][/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=navy] Msgbox[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] ([/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=purple]0[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3],"",[/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=darkred]$Num[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] )[/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=blue]Until [/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=darkred]$Num[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] =[/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=purple] 5[/COLOR][/SIZE][/FONT][/B][/CENTER]
كالعادة استخدم ExitLoop وجرب كذا وكذا إلى أن تتعود ,,
طيب أنا في السابق قلتلك ما نقدر نخليه يعمل إلا الأبد إلا بالتحايل !!! :d:
كيف نعطيه في شرط الخروج شي مستحيل ,, مثل
1>2 :d:
فلو مهما حصل لن يخرج لأنه مستحيل أن يكون الواحد أكبر من الإثنين ..
كود:
[CENTER][B][FONT=Times New Roman][SIZE=3][COLOR=blue]Do [/COLOR][/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=navy]Msgbox[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] ([/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=purple]0[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3],"",[/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=purple]1[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3] )[/SIZE][/FONT][/B]
[B][FONT=Times New Roman][SIZE=3][COLOR=blue]Until[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=purple] 1[COLOR=red]>[/COLOR]2[/COLOR][/SIZE][/FONT][/B][/CENTER]
تحياتي لكم !!