我想從列表中定義一個生成器,它將一次輸出一個元素,然後以的適當方式使用此生成器對象。 a = ["Hello", "world", "!"]
b = (x for x in a)
c = next(b, None)
while c != None:
print c,
c = next(b, None)
這有什麼錯的或可改善這裏的while的方法呢?有沒有辦法避免在循環
在原始條件變爲false之前,有沒有辦法擺脫while循環? 例如,如果我有: while (a==true)
{
doSomething() ;
if (d==false) get out of loop ;
doSomething_that_i_don't_want_done_if_d_is_false_but_do_if_a_and_d_are_true()
過去幾天一直試圖讓我的腦袋周圍循環,但代碼似乎效率非常低,我試圖實現。我假設我過分複雜這一點,儘管我沒有嘗試過似乎工作。 我的論壇中的每個主題都可以將相關主題ID存儲在單獨的表中。帖子ID也存儲在此表中,因爲該特定帖子引用了它們被認爲相關的原因。 數據庫表中只包含:topic_id,related_id,post_id // Get related IDs and post IDs for cur
這個問題我的意思是,如果,例如,某人的用戶名是「bob」,那麼while循環條件將是($ i < 10),並且如果用戶名是別的東西,那麼while循環條件將是$ i> 10) if($username == "bob")
{
//make this while loop condition: ($i < 10)
// it means: while($i <10){ so s