Reorganize statements in a loop without hard coding












3












$begingroup$


I am using a Raspberry Pi 3 model b to control LEDs connected on a breadboard. I want the lights to tell me what chore I have to do today: when to take out the trash, recyclables, vacuum, and clean the bathroom. There's is also another rotation happening every 6 days that I need to keep track of. The code does run and fulfill its purpose, but it is really inconvenient that I have to rewrite the functions Fixed(), vacuum(), and chores() to have the code start in the position I want. My question is how can I make the code run in the right starting position of the cycles without having to rewrite the code itself?



#!/usr/bin/python
# -*- coding: utf-8 -*-

"By Andre Akue"

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(True)
import time
import datetime
from os import system
from multiprocessing import Process

speed = 2 #blinking speed
day_duration = 60*60*24
check_time = 600 #check for day change every 600 secs

class lights: #setting up leds

def __init__(self,color_name,color_pin):
self.name = color_name
self.pin = color_pin
GPIO.setup(self.pin, GPIO.OUT, initial = 0)

def solid(self): #stay on when it's the first day or when the trash is being collected the next day (warning)
GPIO.output(self.pin,1)
time.sleep(check_time)
GPIO.output(self.pin,0)

def flash(self): #blink when it's the second day or when the trash is being collected
stp = time.time() ; etp = time.time() + check_time # stp/etp = starting / ending time pattern
while time.time() < etp:
GPIO.output(self.pin,0)
time.sleep(0.8/speed)
GPIO.output(self.pin,1)
time.sleep(0.2/speed)
GPIO.output(self.pin,0)

L1 = lights("white", 21)
L2 = lights("yellow", 16)
L3 = lights("red", 12)
L4 = lights("blue", 25)
L5 = lights("green", 24)
L6 = lights("snow", 23)

def chores():#a 6 day cycle divided into 3 steps of 2 days each
while 1:
#Sweeping the floor - First Day
L2.solid()#yellow stays on
#Sweeping the floor - Second Day
L2.flash()#yellow keeps blinking
#Setting the table - First Day
L3.solid()#red stays on
#Setting the table - Second Day
L3.flash()#red keeps blinking
#Washing dishes - First Day
GPIO.output((L2.pin,L3.pin),1)#red and yellow stay on
time.sleep(check_time)
GPIO.output((L2.pin,L3.pin),0)
#Washing dishes - Second Day
stp = time.time() ; etp = time.time() + check_time # stp/etp = starting / ending time pattern
while time.time() < etp:#red and yellow keep blinking
GPIO.output((L2.pin,L3.pin),0)
time.sleep(0.8/speed)
GPIO.output((L2.pin,L3.pin),1)
time.sleep(0.2/speed)
GPIO.output((L2.pin,L3.pin),0)

def log():# print weekday and day count in command prompt
count = 0
while 1:
for day in week_order:
count += 1
print ('nDay: %sttDay of the week: %i' % (day,count))
time.sleep(day_duration)

def vacuum():
while 1:
#only happens Friday to Sunday every 3 weeks
for day in list(range(1,22)):
if day not in [4,5,6]:
time.sleep(day_duration)
elif day == 4:
L5.solid()
elif day == 5:
L5.solid()
elif day == 6:
L5.flash()



def start_tomorrow(): #cycle starts the day after the code has been started
tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
while datetime.datetime.now() < tomorrow:
time.sleep(60)
print ('nchore cycle started')

def fixed(): #all weekly, fixed items
while 1:
if datetime.datetime.now().strftime('%a') == 'Mon':
L1.flash()#trash
L6.solid()#recycle
elif datetime.datetime.now().strftime('%a') == 'Tue':
L6.flash()#recycle
elif datetime.datetime.now().strftime('%a') == 'Wed':
L1.solid()#trash
L4.solid()#bath
elif datetime.datetime.now().strftime('%a') == 'Thu':
L1.flash()#trash
L4.flash()#bath
elif datetime.datetime.now().strftime('%a') == 'Fri':

elif datetime.datetime.now().strftime('%a') == 'Sat':

elif datetime.datetime.now().strftime('%a') == 'Sun':
L1.solid()#trash

try:#using processes so that different cycles can run independently
if __name__ == '__main__':
Process(target=log).start()
Process(target=chores).start()
Process(target=bath).start()
Process(target=recycle).start()
Process(target=vacuum).start()
Process(target=trash).start()

except KeyboardInterrupt:
system('clear')
print ("nntexited via keyboard interruptnn")
GPIO.cleanup()

#when resetting:
#3-chore cycle
# place the chore happening tomorrow in first place in the sequence

#'bath','trash','recycle', and 'log'
# place tomorrow in first in the list of weekdays
# 'week_order'

#vaccum cycle
# count the number of days till the next 'first vacuum day',
# and start with this number in the list of the "if" loops









share|improve this question









New contributor




Phil A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    Welcome to Code Review! (I'd opt for a WALL-E with same LEDs telling chores taken care of.) I think I got that you're dissatisfied with hard coding the entry point into the cycle of events (what about their order?).
    $endgroup$
    – greybeard
    9 hours ago










  • $begingroup$
    How fixed is ever called?
    $endgroup$
    – vnp
    1 hour ago










  • $begingroup$
    There are syntax errors and undefined symbols in your code, so obviously it doesn't work. Can you post a version that does run?
    $endgroup$
    – Austin Hastings
    18 mins ago
















3












$begingroup$


I am using a Raspberry Pi 3 model b to control LEDs connected on a breadboard. I want the lights to tell me what chore I have to do today: when to take out the trash, recyclables, vacuum, and clean the bathroom. There's is also another rotation happening every 6 days that I need to keep track of. The code does run and fulfill its purpose, but it is really inconvenient that I have to rewrite the functions Fixed(), vacuum(), and chores() to have the code start in the position I want. My question is how can I make the code run in the right starting position of the cycles without having to rewrite the code itself?



#!/usr/bin/python
# -*- coding: utf-8 -*-

"By Andre Akue"

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(True)
import time
import datetime
from os import system
from multiprocessing import Process

speed = 2 #blinking speed
day_duration = 60*60*24
check_time = 600 #check for day change every 600 secs

class lights: #setting up leds

def __init__(self,color_name,color_pin):
self.name = color_name
self.pin = color_pin
GPIO.setup(self.pin, GPIO.OUT, initial = 0)

def solid(self): #stay on when it's the first day or when the trash is being collected the next day (warning)
GPIO.output(self.pin,1)
time.sleep(check_time)
GPIO.output(self.pin,0)

def flash(self): #blink when it's the second day or when the trash is being collected
stp = time.time() ; etp = time.time() + check_time # stp/etp = starting / ending time pattern
while time.time() < etp:
GPIO.output(self.pin,0)
time.sleep(0.8/speed)
GPIO.output(self.pin,1)
time.sleep(0.2/speed)
GPIO.output(self.pin,0)

L1 = lights("white", 21)
L2 = lights("yellow", 16)
L3 = lights("red", 12)
L4 = lights("blue", 25)
L5 = lights("green", 24)
L6 = lights("snow", 23)

def chores():#a 6 day cycle divided into 3 steps of 2 days each
while 1:
#Sweeping the floor - First Day
L2.solid()#yellow stays on
#Sweeping the floor - Second Day
L2.flash()#yellow keeps blinking
#Setting the table - First Day
L3.solid()#red stays on
#Setting the table - Second Day
L3.flash()#red keeps blinking
#Washing dishes - First Day
GPIO.output((L2.pin,L3.pin),1)#red and yellow stay on
time.sleep(check_time)
GPIO.output((L2.pin,L3.pin),0)
#Washing dishes - Second Day
stp = time.time() ; etp = time.time() + check_time # stp/etp = starting / ending time pattern
while time.time() < etp:#red and yellow keep blinking
GPIO.output((L2.pin,L3.pin),0)
time.sleep(0.8/speed)
GPIO.output((L2.pin,L3.pin),1)
time.sleep(0.2/speed)
GPIO.output((L2.pin,L3.pin),0)

def log():# print weekday and day count in command prompt
count = 0
while 1:
for day in week_order:
count += 1
print ('nDay: %sttDay of the week: %i' % (day,count))
time.sleep(day_duration)

def vacuum():
while 1:
#only happens Friday to Sunday every 3 weeks
for day in list(range(1,22)):
if day not in [4,5,6]:
time.sleep(day_duration)
elif day == 4:
L5.solid()
elif day == 5:
L5.solid()
elif day == 6:
L5.flash()



def start_tomorrow(): #cycle starts the day after the code has been started
tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
while datetime.datetime.now() < tomorrow:
time.sleep(60)
print ('nchore cycle started')

def fixed(): #all weekly, fixed items
while 1:
if datetime.datetime.now().strftime('%a') == 'Mon':
L1.flash()#trash
L6.solid()#recycle
elif datetime.datetime.now().strftime('%a') == 'Tue':
L6.flash()#recycle
elif datetime.datetime.now().strftime('%a') == 'Wed':
L1.solid()#trash
L4.solid()#bath
elif datetime.datetime.now().strftime('%a') == 'Thu':
L1.flash()#trash
L4.flash()#bath
elif datetime.datetime.now().strftime('%a') == 'Fri':

elif datetime.datetime.now().strftime('%a') == 'Sat':

elif datetime.datetime.now().strftime('%a') == 'Sun':
L1.solid()#trash

try:#using processes so that different cycles can run independently
if __name__ == '__main__':
Process(target=log).start()
Process(target=chores).start()
Process(target=bath).start()
Process(target=recycle).start()
Process(target=vacuum).start()
Process(target=trash).start()

except KeyboardInterrupt:
system('clear')
print ("nntexited via keyboard interruptnn")
GPIO.cleanup()

#when resetting:
#3-chore cycle
# place the chore happening tomorrow in first place in the sequence

#'bath','trash','recycle', and 'log'
# place tomorrow in first in the list of weekdays
# 'week_order'

#vaccum cycle
# count the number of days till the next 'first vacuum day',
# and start with this number in the list of the "if" loops









share|improve this question









New contributor




Phil A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    Welcome to Code Review! (I'd opt for a WALL-E with same LEDs telling chores taken care of.) I think I got that you're dissatisfied with hard coding the entry point into the cycle of events (what about their order?).
    $endgroup$
    – greybeard
    9 hours ago










  • $begingroup$
    How fixed is ever called?
    $endgroup$
    – vnp
    1 hour ago










  • $begingroup$
    There are syntax errors and undefined symbols in your code, so obviously it doesn't work. Can you post a version that does run?
    $endgroup$
    – Austin Hastings
    18 mins ago














3












3








3


1



$begingroup$


I am using a Raspberry Pi 3 model b to control LEDs connected on a breadboard. I want the lights to tell me what chore I have to do today: when to take out the trash, recyclables, vacuum, and clean the bathroom. There's is also another rotation happening every 6 days that I need to keep track of. The code does run and fulfill its purpose, but it is really inconvenient that I have to rewrite the functions Fixed(), vacuum(), and chores() to have the code start in the position I want. My question is how can I make the code run in the right starting position of the cycles without having to rewrite the code itself?



#!/usr/bin/python
# -*- coding: utf-8 -*-

"By Andre Akue"

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(True)
import time
import datetime
from os import system
from multiprocessing import Process

speed = 2 #blinking speed
day_duration = 60*60*24
check_time = 600 #check for day change every 600 secs

class lights: #setting up leds

def __init__(self,color_name,color_pin):
self.name = color_name
self.pin = color_pin
GPIO.setup(self.pin, GPIO.OUT, initial = 0)

def solid(self): #stay on when it's the first day or when the trash is being collected the next day (warning)
GPIO.output(self.pin,1)
time.sleep(check_time)
GPIO.output(self.pin,0)

def flash(self): #blink when it's the second day or when the trash is being collected
stp = time.time() ; etp = time.time() + check_time # stp/etp = starting / ending time pattern
while time.time() < etp:
GPIO.output(self.pin,0)
time.sleep(0.8/speed)
GPIO.output(self.pin,1)
time.sleep(0.2/speed)
GPIO.output(self.pin,0)

L1 = lights("white", 21)
L2 = lights("yellow", 16)
L3 = lights("red", 12)
L4 = lights("blue", 25)
L5 = lights("green", 24)
L6 = lights("snow", 23)

def chores():#a 6 day cycle divided into 3 steps of 2 days each
while 1:
#Sweeping the floor - First Day
L2.solid()#yellow stays on
#Sweeping the floor - Second Day
L2.flash()#yellow keeps blinking
#Setting the table - First Day
L3.solid()#red stays on
#Setting the table - Second Day
L3.flash()#red keeps blinking
#Washing dishes - First Day
GPIO.output((L2.pin,L3.pin),1)#red and yellow stay on
time.sleep(check_time)
GPIO.output((L2.pin,L3.pin),0)
#Washing dishes - Second Day
stp = time.time() ; etp = time.time() + check_time # stp/etp = starting / ending time pattern
while time.time() < etp:#red and yellow keep blinking
GPIO.output((L2.pin,L3.pin),0)
time.sleep(0.8/speed)
GPIO.output((L2.pin,L3.pin),1)
time.sleep(0.2/speed)
GPIO.output((L2.pin,L3.pin),0)

def log():# print weekday and day count in command prompt
count = 0
while 1:
for day in week_order:
count += 1
print ('nDay: %sttDay of the week: %i' % (day,count))
time.sleep(day_duration)

def vacuum():
while 1:
#only happens Friday to Sunday every 3 weeks
for day in list(range(1,22)):
if day not in [4,5,6]:
time.sleep(day_duration)
elif day == 4:
L5.solid()
elif day == 5:
L5.solid()
elif day == 6:
L5.flash()



def start_tomorrow(): #cycle starts the day after the code has been started
tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
while datetime.datetime.now() < tomorrow:
time.sleep(60)
print ('nchore cycle started')

def fixed(): #all weekly, fixed items
while 1:
if datetime.datetime.now().strftime('%a') == 'Mon':
L1.flash()#trash
L6.solid()#recycle
elif datetime.datetime.now().strftime('%a') == 'Tue':
L6.flash()#recycle
elif datetime.datetime.now().strftime('%a') == 'Wed':
L1.solid()#trash
L4.solid()#bath
elif datetime.datetime.now().strftime('%a') == 'Thu':
L1.flash()#trash
L4.flash()#bath
elif datetime.datetime.now().strftime('%a') == 'Fri':

elif datetime.datetime.now().strftime('%a') == 'Sat':

elif datetime.datetime.now().strftime('%a') == 'Sun':
L1.solid()#trash

try:#using processes so that different cycles can run independently
if __name__ == '__main__':
Process(target=log).start()
Process(target=chores).start()
Process(target=bath).start()
Process(target=recycle).start()
Process(target=vacuum).start()
Process(target=trash).start()

except KeyboardInterrupt:
system('clear')
print ("nntexited via keyboard interruptnn")
GPIO.cleanup()

#when resetting:
#3-chore cycle
# place the chore happening tomorrow in first place in the sequence

#'bath','trash','recycle', and 'log'
# place tomorrow in first in the list of weekdays
# 'week_order'

#vaccum cycle
# count the number of days till the next 'first vacuum day',
# and start with this number in the list of the "if" loops









share|improve this question









New contributor




Phil A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




I am using a Raspberry Pi 3 model b to control LEDs connected on a breadboard. I want the lights to tell me what chore I have to do today: when to take out the trash, recyclables, vacuum, and clean the bathroom. There's is also another rotation happening every 6 days that I need to keep track of. The code does run and fulfill its purpose, but it is really inconvenient that I have to rewrite the functions Fixed(), vacuum(), and chores() to have the code start in the position I want. My question is how can I make the code run in the right starting position of the cycles without having to rewrite the code itself?



#!/usr/bin/python
# -*- coding: utf-8 -*-

"By Andre Akue"

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(True)
import time
import datetime
from os import system
from multiprocessing import Process

speed = 2 #blinking speed
day_duration = 60*60*24
check_time = 600 #check for day change every 600 secs

class lights: #setting up leds

def __init__(self,color_name,color_pin):
self.name = color_name
self.pin = color_pin
GPIO.setup(self.pin, GPIO.OUT, initial = 0)

def solid(self): #stay on when it's the first day or when the trash is being collected the next day (warning)
GPIO.output(self.pin,1)
time.sleep(check_time)
GPIO.output(self.pin,0)

def flash(self): #blink when it's the second day or when the trash is being collected
stp = time.time() ; etp = time.time() + check_time # stp/etp = starting / ending time pattern
while time.time() < etp:
GPIO.output(self.pin,0)
time.sleep(0.8/speed)
GPIO.output(self.pin,1)
time.sleep(0.2/speed)
GPIO.output(self.pin,0)

L1 = lights("white", 21)
L2 = lights("yellow", 16)
L3 = lights("red", 12)
L4 = lights("blue", 25)
L5 = lights("green", 24)
L6 = lights("snow", 23)

def chores():#a 6 day cycle divided into 3 steps of 2 days each
while 1:
#Sweeping the floor - First Day
L2.solid()#yellow stays on
#Sweeping the floor - Second Day
L2.flash()#yellow keeps blinking
#Setting the table - First Day
L3.solid()#red stays on
#Setting the table - Second Day
L3.flash()#red keeps blinking
#Washing dishes - First Day
GPIO.output((L2.pin,L3.pin),1)#red and yellow stay on
time.sleep(check_time)
GPIO.output((L2.pin,L3.pin),0)
#Washing dishes - Second Day
stp = time.time() ; etp = time.time() + check_time # stp/etp = starting / ending time pattern
while time.time() < etp:#red and yellow keep blinking
GPIO.output((L2.pin,L3.pin),0)
time.sleep(0.8/speed)
GPIO.output((L2.pin,L3.pin),1)
time.sleep(0.2/speed)
GPIO.output((L2.pin,L3.pin),0)

def log():# print weekday and day count in command prompt
count = 0
while 1:
for day in week_order:
count += 1
print ('nDay: %sttDay of the week: %i' % (day,count))
time.sleep(day_duration)

def vacuum():
while 1:
#only happens Friday to Sunday every 3 weeks
for day in list(range(1,22)):
if day not in [4,5,6]:
time.sleep(day_duration)
elif day == 4:
L5.solid()
elif day == 5:
L5.solid()
elif day == 6:
L5.flash()



def start_tomorrow(): #cycle starts the day after the code has been started
tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
while datetime.datetime.now() < tomorrow:
time.sleep(60)
print ('nchore cycle started')

def fixed(): #all weekly, fixed items
while 1:
if datetime.datetime.now().strftime('%a') == 'Mon':
L1.flash()#trash
L6.solid()#recycle
elif datetime.datetime.now().strftime('%a') == 'Tue':
L6.flash()#recycle
elif datetime.datetime.now().strftime('%a') == 'Wed':
L1.solid()#trash
L4.solid()#bath
elif datetime.datetime.now().strftime('%a') == 'Thu':
L1.flash()#trash
L4.flash()#bath
elif datetime.datetime.now().strftime('%a') == 'Fri':

elif datetime.datetime.now().strftime('%a') == 'Sat':

elif datetime.datetime.now().strftime('%a') == 'Sun':
L1.solid()#trash

try:#using processes so that different cycles can run independently
if __name__ == '__main__':
Process(target=log).start()
Process(target=chores).start()
Process(target=bath).start()
Process(target=recycle).start()
Process(target=vacuum).start()
Process(target=trash).start()

except KeyboardInterrupt:
system('clear')
print ("nntexited via keyboard interruptnn")
GPIO.cleanup()

#when resetting:
#3-chore cycle
# place the chore happening tomorrow in first place in the sequence

#'bath','trash','recycle', and 'log'
# place tomorrow in first in the list of weekdays
# 'week_order'

#vaccum cycle
# count the number of days till the next 'first vacuum day',
# and start with this number in the list of the "if" loops






python beginner python-3.x raspberry-pi scheduled-tasks






share|improve this question









New contributor




Phil A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Phil A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 hour ago









vnp

39.9k232102




39.9k232102






New contributor




Phil A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 12 hours ago









Phil APhil A

164




164




New contributor




Phil A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Phil A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Phil A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • $begingroup$
    Welcome to Code Review! (I'd opt for a WALL-E with same LEDs telling chores taken care of.) I think I got that you're dissatisfied with hard coding the entry point into the cycle of events (what about their order?).
    $endgroup$
    – greybeard
    9 hours ago










  • $begingroup$
    How fixed is ever called?
    $endgroup$
    – vnp
    1 hour ago










  • $begingroup$
    There are syntax errors and undefined symbols in your code, so obviously it doesn't work. Can you post a version that does run?
    $endgroup$
    – Austin Hastings
    18 mins ago


















  • $begingroup$
    Welcome to Code Review! (I'd opt for a WALL-E with same LEDs telling chores taken care of.) I think I got that you're dissatisfied with hard coding the entry point into the cycle of events (what about their order?).
    $endgroup$
    – greybeard
    9 hours ago










  • $begingroup$
    How fixed is ever called?
    $endgroup$
    – vnp
    1 hour ago










  • $begingroup$
    There are syntax errors and undefined symbols in your code, so obviously it doesn't work. Can you post a version that does run?
    $endgroup$
    – Austin Hastings
    18 mins ago
















$begingroup$
Welcome to Code Review! (I'd opt for a WALL-E with same LEDs telling chores taken care of.) I think I got that you're dissatisfied with hard coding the entry point into the cycle of events (what about their order?).
$endgroup$
– greybeard
9 hours ago




$begingroup$
Welcome to Code Review! (I'd opt for a WALL-E with same LEDs telling chores taken care of.) I think I got that you're dissatisfied with hard coding the entry point into the cycle of events (what about their order?).
$endgroup$
– greybeard
9 hours ago












$begingroup$
How fixed is ever called?
$endgroup$
– vnp
1 hour ago




$begingroup$
How fixed is ever called?
$endgroup$
– vnp
1 hour ago












$begingroup$
There are syntax errors and undefined symbols in your code, so obviously it doesn't work. Can you post a version that does run?
$endgroup$
– Austin Hastings
18 mins ago




$begingroup$
There are syntax errors and undefined symbols in your code, so obviously it doesn't work. Can you post a version that does run?
$endgroup$
– Austin Hastings
18 mins ago










0






active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Phil A is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214173%2freorganize-statements-in-a-loop-without-hard-coding%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








Phil A is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Phil A is a new contributor. Be nice, and check out our Code of Conduct.













Phil A is a new contributor. Be nice, and check out our Code of Conduct.












Phil A is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214173%2freorganize-statements-in-a-loop-without-hard-coding%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?