我只想知道是否有一種方法可以使循環處於If語句條件?在IF聲明條件內循環
樣品:
if((string.contains(stringlist.hello().value(0),Qt::CaseInsensitive))||(string.contains(stringlist.hello().value(1),Qt::CaseInsensitive))||(string.contains(stringlist.hello().value(2),Qt::CaseInsensitive)))
{
...
}
爲:
if
(
for(int i=0; i < stringlist.hello().size(); i++)
{
string.contains(stringlist.hello().value(i),Qt::CaseInsensitive)
}
)
{
...
}
的方式招呼()函數檢索來自數據庫的數據的列表。 該程序的目的是檢查一個字符串是否包含來自數據庫的一些關鍵字。
即使這是有效的語法,這將是一個壞主意,因爲它很難閱讀。這就是函數的作用...創建一個函數來執行循環,給它一個有意義的名字,然後把它稱爲'if'的謂詞。 – Nemo
每隔一段時間在空間中投擲會讓閱讀起來更容易 –
tnx建議 –